package com.example.zjsr.service.impl;

import com.example.zjsr.common.ServerResponse;
import com.example.zjsr.dao.ExcelDao;
import com.example.zjsr.domain.*;
import com.example.zjsr.service.ExcelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class ExcelServiceImpl implements ExcelService {


    @Autowired
    public ExcelDao excelDao;

    @Override
    public ServerResponse leadAnchors(List<Anchors> anchorsList) {
        int checkExportPriceDataStatus=excelDao.leadAnchors(anchorsList);
        if(checkExportPriceDataStatus!=0){
         return ServerResponse.createBySuccessMsg("上传成功！");
        }else{
            return ServerResponse.createByErrorMsg("上传失败");
        }
    }


    @Override
    public ServerResponse leadAnchorsInfo(List<AnchorsInfo> anchorsInfoList) {
        int checkLeadAnchorsInfo=excelDao.leadAnchorsInfo(anchorsInfoList);
        if(checkLeadAnchorsInfo!=0){
            return ServerResponse.createBySuccessMsg("上传成功！");
        }else{
            return ServerResponse.createByErrorMsg("上传失败");
        }
    }

    @Transactional
    @Override
    public ServerResponse leadFruit(List<ExcelFruit> excelFruitList) {
        excelDao.deleteFruit();
        Integer checkLeadFruitStatus=excelDao.leadFruit(excelFruitList);
        if(checkLeadFruitStatus!=0){
            return ServerResponse.createBySuccessMsg("成功上传水果种类信息");
        }else{
            return ServerResponse.createByErrorMsg("上传水果种类信息失败");
        }
    }

    @Transactional
    @Override
    public ServerResponse leadFruitInfo(List<ExcelFruitInfo> excelFruitInfoArrayList,Integer fruitId) {
        excelDao.deleteFruitInfo(fruitId);
        Integer checkLeadFruitInfoStatus=excelDao.leadFruitInfo(excelFruitInfoArrayList);
        if(checkLeadFruitInfoStatus!=0){
            return ServerResponse.createBySuccessMsg("成功上传水果详细信息");
        }else{
            return ServerResponse.createByErrorMsg("上传水果详细信息失败");
        }
    }


    @Override
    public ServerResponse uploadFruitPicture(Integer fruitId, String path) {
        int checkStatus=excelDao.insertFruitPicture(fruitId,path);
        if(checkStatus!=0){
            return ServerResponse.createBySuccessMsg("成功添加图片");
        }else{
            return ServerResponse.createByErrorMsg("添加图片失败");
        }
    }


    @Override
    public List<ExcelFruit> downloadFruit() {
        return excelDao.downloadFruit();
    }
}
